package com.dly.blog.provider;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dly.blog.domain.Token;
import com.dly.blog.mapper.TokenMapper;
import com.dly.blog.provider.user.TokenProvider;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/12 23:42
 */
@Component
@AllArgsConstructor
public class TokenProviderImpl implements TokenProvider {

    private final TokenMapper tokenMapper;

    @Override
    public List<Token> findAllValidTokenByUser(String id) {
        return tokenMapper.findAllValidTokenByUser(id);
    }

    @Override
    public int insertBatch(List<Token> tokens) {
        return tokenMapper.insertBatch(tokens);
    }

    @Override
    public int updateBathValid(String userId) {
        return tokenMapper.updateBathValid(userId);
    }

    @Override
    public int insert(Token token) {
        return tokenMapper.insert(token);
    }

    @Override
    public Token selectByToken(String jwt) {
        return tokenMapper.selectOne(new LambdaQueryWrapper<Token>().eq(Token::getToken, jwt));
    }
}
